home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / machine / toaplan1.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  8KB  |  260 lines

  1. /***************************************************************************
  2.                     ToaPlan  (1988-1991 hardware)
  3.  ***************************************************************************/
  4.  
  5. #include "driver.h"
  6. #include "cpu/m68000/m68000.h"
  7. #include "cpu/tms32010/tms32010.h"
  8.  
  9. #define CLEAR 0
  10. #define ASSERT 1
  11.  
  12.  
  13. READ_HANDLER( video_ofs3_r );
  14. WRITE_HANDLER( video_ofs3_w );
  15. WRITE_HANDLER( toaplan1_videoram3_w );
  16.  
  17. int toaplan1_coin_count; /* coin count increments on startup ? , so dont count it */
  18.  
  19. int toaplan1_int_enable;
  20. static int unk;
  21. static int credits;
  22. static int latch;
  23. static int dsp_execute;
  24. static unsigned int dsp_addr_w, main_ram_seg;
  25.  
  26. extern unsigned char *toaplan1_sharedram;
  27.  
  28.  
  29.  
  30. READ_HANDLER( demonwld_dsp_r )
  31. {
  32.     /* DSP can read data from main CPU RAM via DSP IO port 1 */
  33.  
  34.     unsigned int input_data = 0;
  35.  
  36.     switch (main_ram_seg) {
  37.         case 0xc00000:    input_data = READ_WORD(&(cpu_bankbase[1][(dsp_addr_w)])); break;
  38.  
  39.         default:        logerror("DSP PC:%04x Warning !!! IO reading from %08x (port 1)\n",cpu_getpreviouspc(),main_ram_seg + dsp_addr_w);
  40.     }
  41.     logerror("DSP PC:%04x IO read %04x at %08x (port 1)\n",cpu_getpreviouspc(),input_data,main_ram_seg + dsp_addr_w);
  42.     return input_data;
  43. }
  44.  
  45. WRITE_HANDLER( demonwld_dsp_w )
  46. {
  47.     if (offset == 0) {
  48.         /* This sets the main CPU RAM address the DSP should */
  49.         /*        read/write, via the DSP IO port 0 */
  50.         /* Top three bits of data need to be shifted left 9 places */
  51.         /*        to select which memory bank from main CPU address */
  52.         /*        space to use */
  53.         /* Lower thirteen bits of this data is shifted left one position */
  54.         /*        to move it to an even address word boundary */
  55.  
  56.         dsp_addr_w = ((data & 0x1fff) << 1);
  57.         main_ram_seg = ((data & 0xe000) << 9);
  58.         logerror("DSP PC:%04x IO write %04x (%08x) at port 0\n",cpu_getpreviouspc(),data,main_ram_seg + dsp_addr_w);
  59.     }
  60.     if (offset == 1) {
  61.         /* Data written to main CPU RAM via DSP IO port 1*/
  62.  
  63.         dsp_execute = 0;
  64.         switch (main_ram_seg) {
  65.             case 0xc00000:    WRITE_WORD(&(cpu_bankbase[1][(dsp_addr_w)]),data);
  66.                             if ((dsp_addr_w < 3) && (data == 0)) dsp_execute = 1; break;
  67.             default:        logerror("DSP PC:%04x Warning !!! IO writing to %08x (port 1)\n",cpu_getpreviouspc(),main_ram_seg + dsp_addr_w);
  68.         }
  69.         logerror("DSP PC:%04x IO write %04x at %08x (port 1)\n",cpu_getpreviouspc(),data,main_ram_seg + dsp_addr_w);
  70.     }
  71.     if (offset == 3) {
  72.         /* data 0xffff    means inhibit BIO line to DSP and enable  */
  73.         /*                communication to main processor */
  74.         /*                Actually only DSP data bit 15 controls this */
  75.         /* data 0x0000    means set DSP BIO line active and disable */
  76.         /*                communication to main processor*/
  77.         logerror("DSP PC:%04x IO write %04x at port 3\n",cpu_getpreviouspc(),data);
  78.         if (data & 0x8000) {
  79.             cpu_set_irq_line(2, TMS320C10_ACTIVE_BIO, CLEAR_LINE);
  80.         }
  81.         if (data == 0) {
  82.             if (dsp_execute) {
  83.                 logerror("Turning 68000 on\n");
  84.                 timer_suspendcpu(0, CLEAR, SUSPEND_REASON_HALT);
  85.                 dsp_execute = 0;
  86.             }
  87.             cpu_set_irq_line(2, TMS320C10_ACTIVE_BIO, ASSERT_LINE);
  88.         }
  89.     }
  90. }
  91.  
  92. WRITE_HANDLER( demonwld_dsp_ctrl_w )
  93. {
  94. #if 0
  95.     logerror("68000:%08x  Writing %08x to %08x.\n",cpu_get_pc() ,data ,0xe0000a + offset);
  96. #endif
  97.  
  98.     switch (data) {
  99.         case 0x0000:     /* This means assert the INT line to the DSP */
  100.                         logerror("Turning DSP on and 68000 off\n");
  101.                         timer_suspendcpu(2, CLEAR, SUSPEND_REASON_HALT);
  102.                         cpu_set_irq_line(2, TMS320C10_ACTIVE_INT, ASSERT_LINE);
  103.                         timer_suspendcpu(0, ASSERT, SUSPEND_REASON_HALT);
  104.                         break;
  105.         case 0x0001:     /* This means inhibit the INT line to the DSP */
  106.                         logerror("Turning DSP off\n");
  107.                         cpu_set_irq_line(2, TMS320C10_ACTIVE_INT, CLEAR_LINE);
  108.                         timer_suspendcpu(2, ASSERT, SUSPEND_REASON_HALT);
  109.                         break;
  110.         default:        logerror("68000:%04x  writing unknown command %08x to %08x\n",cpu_getpreviouspc() ,data ,0xe0000a + offset);
  111.     }
  112. }
  113.  
  114.  
  115.  
  116. int toaplan1_interrupt(void)
  117. {
  118.     if (toaplan1_int_enable)
  119.     {
  120.         return MC68000_IRQ_4;
  121.     }
  122.     return MC68000_INT_NONE;
  123. }
  124.  
  125. WRITE_HANDLER( toaplan1_int_enable_w )
  126. {
  127.     toaplan1_int_enable = data;
  128. }
  129.  
  130. READ_HANDLER( toaplan1_unk_r )
  131. {
  132.     return unk ^= 1;
  133. }
  134.  
  135. READ_HANDLER( samesame_port_6_r )
  136. {
  137.     /* Bit 0x80 is secondary CPU (HD647180) ready signal */
  138.     logerror("PC:%04x Warning !!! IO reading from $14000a\n",cpu_getpreviouspc());
  139.     return (0x80 | input_port_6_r(0));
  140. }
  141.  
  142. READ_HANDLER( vimana_input_port_5_r )
  143. {
  144.     int data, p;
  145.  
  146.     p = input_port_5_r(0);
  147.  
  148.     latch ^= p;
  149.     data = (latch & p );
  150.  
  151.     /* simulate the mcu keeping track of credits */
  152.     /* latch is so is doesn't add more than one */
  153.     /* credit per keypress */
  154.  
  155.     if (data & 0x18)
  156.     {
  157.         credits++ ;
  158.     }
  159.  
  160.     latch = p;
  161.  
  162.     return p;
  163. }
  164.  
  165. READ_HANDLER( vimana_mcu_r )
  166. {
  167.     int data = 0 ;
  168.     switch (offset >> 1)
  169.     {
  170.         case 0:
  171.             data = 0xff;
  172.             break;
  173.         case 1:
  174.             data = 0;
  175.             break;
  176.         case 2:
  177.             data = credits;
  178.             break;
  179.     }
  180.     return data;
  181. }
  182. WRITE_HANDLER( vimana_mcu_w )
  183. {
  184.     switch (offset >> 1)
  185.     {
  186.         case 0:
  187.             break;
  188.         case 1:
  189.             break;
  190.         case 2:
  191.             credits = data;
  192.             break;
  193.     }
  194. }
  195.  
  196. READ_HANDLER( toaplan1_shared_r )
  197. {
  198.     return toaplan1_sharedram[offset>>1];
  199. }
  200.  
  201. WRITE_HANDLER( toaplan1_shared_w )
  202. {
  203.     toaplan1_sharedram[offset>>1] = data;
  204. }
  205.  
  206. void toaplan1_init_machine(void)
  207. {
  208.     dsp_addr_w = dsp_execute = 0;
  209.     main_ram_seg = 0;
  210.     toaplan1_int_enable = 0;
  211.     unk = 0;
  212.     credits = 0;
  213.     latch = 0;
  214.     toaplan1_coin_count = 0;
  215.     coin_lockout_global_w(0,0);
  216. }
  217.  
  218. WRITE_HANDLER( rallybik_coin_w )
  219. {
  220.     switch (data) {
  221.         case 0x08: if (toaplan1_coin_count) { coin_counter_w(0,1); coin_counter_w(0,0); } break;
  222.         case 0x09: if (toaplan1_coin_count) { coin_counter_w(2,1); coin_counter_w(2,0); } break;
  223.         case 0x0a: if (toaplan1_coin_count) { coin_counter_w(1,1); coin_counter_w(1,0); } break;
  224.         case 0x0b: if (toaplan1_coin_count) { coin_counter_w(3,1); coin_counter_w(3,0); } break;
  225.         case 0x0c: coin_lockout_w(0,1); coin_lockout_w(2,1); break;
  226.         case 0x0d: coin_lockout_w(0,0); coin_lockout_w(2,0); break;
  227.         case 0x0e: coin_lockout_w(1,1); coin_lockout_w(3,1); break;
  228.         case 0x0f: coin_lockout_w(1,0); coin_lockout_w(3,0); toaplan1_coin_count=1; break;
  229.     }
  230. }
  231.  
  232. WRITE_HANDLER( toaplan1_coin_w )
  233. {
  234.     logerror("Z80 writing %02x to coin control\n",data);
  235.     /* This still isnt too clear yet. */
  236.     /* Coin C has no coin lock ? */
  237.     /* Are some outputs for lights ? (no space on JAMMA for it though) */
  238.  
  239.     switch (data) {
  240.         case 0xee: coin_counter_w(1,1); coin_counter_w(1,0); break; /* Count slot B */
  241.         case 0xed: coin_counter_w(0,1); coin_counter_w(0,0); break; /* Count slot A */
  242.     /* The following are coin counts after coin-lock active (faulty coin-lock ?) */
  243.         case 0xe2: coin_counter_w(1,1); coin_counter_w(1,0); coin_lockout_w(1,1); break;
  244.         case 0xe1: coin_counter_w(0,1); coin_counter_w(0,0); coin_lockout_w(0,1); break;
  245.  
  246.         case 0xec: coin_lockout_global_w(0,0); break;    /* ??? count games played */
  247.         case 0xe8: break;    /* ??? Maximum credits reached with coin/credit ratio */
  248.         case 0xe4: break;    /* ??? Reset coin system */
  249.  
  250.         case 0x0c: coin_lockout_global_w(0,0); break;    /* Unlock all coin slots */
  251.         case 0x08: coin_lockout_w(2,0); break;    /* Unlock coin slot C */
  252.         case 0x09: coin_lockout_w(0,0); break;    /* Unlock coin slot A */
  253.         case 0x0a: coin_lockout_w(1,0); break;    /* Unlock coin slot B */
  254.  
  255.         case 0x02: coin_lockout_w(1,1); break;    /* Lock coin slot B */
  256.         case 0x01: coin_lockout_w(0,1); break;    /* Lock coin slot A */
  257.         case 0x00: coin_lockout_global_w(0,1); break;    /* Lock all coin slots */
  258.     }
  259. }
  260.